﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Data;
using Antu.DataAccess;
using System.Xml;
using System.Drawing;
using Antu.Core.Services;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.ComponentModel;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Globalization;

namespace Antu.WorkFlowFactory
{
    public enum StepType
    {
        End = 2,
        EndNotAccept = -2,
        EndNotTransact = -3,
        EndOther = -4,
        MutiFlowEnd = 12,
        MutiFlowStart = 11,
        Normal = 1,
        Start = 0
    }
    public enum WorkflowType
    {
        FaWen = 12,
        ShenPi = 0,
        ShouWen = 11,
        YueWen = 13
    }
    public enum SendMethod
    {
        AllSend,
        MultiSend,
        SingleSend
    }
    public enum InStepSumbitType
    {
        NeedSumbit,
        DontNeedSumbit,
        MustSumbit
    }
    public enum StepExtendType
    {
        Other,
        StepGroup
    }
    public class Step : IDrawObject, ICloneable
    {
        FlowFactoryProvider _FlowFactoryProvider = (FlowFactoryProvider)ProviderService.ProviderServiceMange.GetProvider("FlowFactoryProvider");
        // Fields
        private string aar;
        private string adr;
        private string amr;
        private string arr;
        private static Hashtable beginStep = new Hashtable();
        private string ctlId;
        private float cx;
        private float cy;
        private static Hashtable endStep = new Hashtable();
        private int exalarmtime;
        private string exclusive_receive;
        private StepExtendType extendtype;
        private string id;
        private InStepSumbitType insteptype;
        private static Hashtable jobStep = new Hashtable();
        private string op_type;
        private Hashtable resources;
        private SendMethod send_method;
        private string single_select;
        private string sname;
        private StepType step_type;
        private string sync_lock;
        private int timeout;
        private TextStyle ts;
        private Hashtable userGroups;
        private string wid;

        // Methods
        public Step(WorkFlowXmlDocumnet workFlowXmlDocumnet, string id)
            : this(workFlowXmlDocumnet.WorkFlowXmlDcoument, id)
        {
        }

        public Step(string wid, string ctlId)
        {
            this.id = "";
            this.wid = "";
            this.ctlId = "";
            this.sname = "";
            this.step_type = StepType.Normal;
            this.op_type = "0";
            this.sync_lock = "0";
            this.exclusive_receive = "0";
            this.send_method = SendMethod.SingleSend;
            this.arr = "0";
            this.amr = "0";
            this.adr = "0";
            this.aar = "0";
            this.cx = 0f;
            this.cy = 0f;
            this.timeout = 0;
            this.exalarmtime = 0;
            this.single_select = "0";
            this.insteptype = InStepSumbitType.NeedSumbit;
            this.extendtype = StepExtendType.Other;
            this.userGroups = new Hashtable();
            this.resources = new Hashtable();
            this.ts = new TextStyle();
            string sql = "SELECT * FROM ST_Step WHERE WId='" + wid + "' AND CtlId='" + ctlId + "'";
            DataTable table = _FlowFactoryProvider.GetDT(sql);
            if (table.Rows.Count > 0)
            {
                this.InitData(table.Rows[0]);
            }
        }

        public Step(XmlDocument xml, string id)
        {
            int num;
            this.id = "";
            this.wid = "";
            this.ctlId = "";
            this.sname = "";
            this.step_type = StepType.Normal;
            this.op_type = "0";
            this.sync_lock = "0";
            this.exclusive_receive = "0";
            this.send_method = SendMethod.SingleSend;
            this.arr = "0";
            this.amr = "0";
            this.adr = "0";
            this.aar = "0";
            this.cx = 0f;
            this.cy = 0f;
            this.timeout = 0;
            this.exalarmtime = 0;
            this.single_select = "0";
            this.insteptype = InStepSumbitType.NeedSumbit;
            this.extendtype = StepExtendType.Other;
            this.userGroups = new Hashtable();
            this.resources = new Hashtable();
            this.ts = new TextStyle();
            string filter = "/workflow/steps/step[@id='" + id + "']";
            this.Id = id;
            this.wid = GetNodeAttriBute(filter, "wid", xml);
            this.Sname = GetNodeAttriBute(filter, "sname", xml);
            this.CtlId = GetNodeAttriBute(filter, "ctlid", xml);
            this.Cx = _FlowFactoryProvider.S2Float(GetNodeAttriBute(filter, "cx", xml));
            this.Cy = _FlowFactoryProvider.S2Float(GetNodeAttriBute(filter, "cy", xml));
            this.Step_Type = (StepType)_FlowFactoryProvider.S2Int(GetNodeAttriBute(filter, "step_type", xml));
            this.Op_Type = GetNodeAttriBute(filter, "op_type", xml);
            this.Sync_Lock = GetNodeAttriBute(filter, "sync_lock", xml);
            this.Exclusive_Receive = GetNodeAttriBute(filter, "exclusive_receive", xml);
            this.Send_Method = (SendMethod)_FlowFactoryProvider.S2Int(GetNodeAttriBute(filter, "send_method", xml));
            this.Arr = GetNodeAttriBute(filter, "arr", xml);
            this.Amr = GetNodeAttriBute(filter, "amr", xml);
            this.Adr = GetNodeAttriBute(filter, "adr", xml);
            this.Aar = GetNodeAttriBute(filter, "aar", xml);
            this.Timeout = _FlowFactoryProvider.S2Int(GetNodeAttriBute(filter, "timeout", xml));
            this.ExAlarmTime = _FlowFactoryProvider.S2Int(GetNodeAttriBute(filter, "exalarmtime", xml));
            this.Single_Select = GetNodeAttriBute(filter, "single_select", xml);
            this.InStepType = (InStepSumbitType)_FlowFactoryProvider.S2Int(GetNodeAttriBute(filter, "insteptype", xml));
            this.ExtentType = (StepExtendType)_FlowFactoryProvider.S2Int(GetNodeAttriBute(filter, "extend_type", xml));
            filter = "/workflow/steps/step[@id='" + id + "']/role";
            XmlNodeList nodes = GetNodes(filter, xml);
            for (num = 0; num < nodes.Count; num++)
            {
                this.userGroups.Add(nodes[num].Attributes["gid"].Value, nodes[num].Attributes["group_name"].Value);
            }
            filter = "/workflow/steps/step[@id='" + id + "']/step_resources/step_resource";
            nodes = GetNodes(filter, xml);
            for (num = 0; num < nodes.Count; num++)
            {
                this.resources.Add(nodes[num].Attributes["path"].Value, nodes[num].Attributes["res_value"].Value);
            }
        }
        public string GetNodeAttriBute(string filter, string nameAttribute, XmlDocument doc)
        {
            try
            {
                return GetNode(filter, doc).Attributes[nameAttribute].Value;
            }
            catch
            {
                return "";
            }
        }
        public XmlNode GetNode(string filter, XmlDocument doc)
        {
            return doc.SelectSingleNode(filter);
        }
        public XmlNodeList GetNodes(string filter, XmlDocument doc)
        {
            return doc.SelectNodes(filter);
        }
        public Step(StepType stepType, string wid, float x, float y)
        {
            this.id = "";
            this.wid = "";
            this.ctlId = "";
            this.sname = "";
            this.step_type = StepType.Normal;
            this.op_type = "0";
            this.sync_lock = "0";
            this.exclusive_receive = "0";
            this.send_method = SendMethod.SingleSend;
            this.arr = "0";
            this.amr = "0";
            this.adr = "0";
            this.aar = "0";
            this.cx = 0f;
            this.cy = 0f;
            this.timeout = 0;
            this.exalarmtime = 0;
            this.single_select = "0";
            this.insteptype = InStepSumbitType.NeedSumbit;
            this.extendtype = StepExtendType.Other;
            this.userGroups = new Hashtable();
            this.resources = new Hashtable();
            this.ts = new TextStyle();
            this.Id = Guid.NewGuid().ToString();
            this.Step_Type = stepType;
            this.CtlId = Guid.NewGuid().ToString();
            this.wid = wid;
            this.Cx = x;
            this.Cy = y;
            this.Sname = this.GetTextWrite(stepType);
        }

        private void AddStepCount(StepType stepType, string textWrite)
        {
            string num = "";
            switch (stepType)
            {
                case StepType.Start:
                    if (textWrite.Contains("开始"))
                    {
                        num = textWrite.Replace("开始", "");
                        if (_FlowFactoryProvider.IsNum(num))
                        {
                            if (beginStep.Contains(this.wid))
                            {
                                beginStep[this.wid] = (_FlowFactoryProvider.S2Int(beginStep[this.wid].ToString()) < _FlowFactoryProvider.S2Int(num)) ? _FlowFactoryProvider.S2Int(num) : beginStep[this.wid];
                                return;
                            }
                            beginStep.Add(this.wid, num);
                        }
                    }
                    return;

                case StepType.End:
                    if (textWrite.Contains("结束"))
                    {
                        num = textWrite.Replace("结束", "");
                        if (_FlowFactoryProvider.IsNum(num))
                        {
                            if (endStep.Contains(this.wid))
                            {
                                endStep[this.wid] = (_FlowFactoryProvider.S2Int(endStep[this.wid].ToString()) < _FlowFactoryProvider.S2Int(num)) ? _FlowFactoryProvider.S2Int(num) : endStep[this.wid];
                                return;
                            }
                            endStep.Add(this.wid, num);
                        }
                    }
                    return;
            }
            if (textWrite.Contains("岗位"))
            {
                num = textWrite.Replace("岗位", "");
                if (_FlowFactoryProvider.IsNum(num))
                {
                    if (!jobStep.Contains(this.wid))
                    {
                        jobStep.Add(this.wid, num);
                    }
                    else
                    {
                        jobStep[this.wid] = (_FlowFactoryProvider.S2Int(jobStep[this.wid].ToString()) < _FlowFactoryProvider.S2Int(num)) ? _FlowFactoryProvider.S2Int(num) : jobStep[this.wid];
                    }
                }
            }
        }

        public object Clone()
        {
            return SerialClone.Instance.Clone(this);
        }

        public bool DeleteResource(string rtid)
        {
            List<string> list = new List<string>();
            foreach (DictionaryEntry entry in this.resources)
            {
                if (entry.Key.ToString() == rtid)
                {
                    list.Add(rtid);
                }
            }
            for (int i = 0; i < list.Count; i++)
            {
                this.resources.Remove(list[i]);
            }
            return true;
        }

        public void Draw(Graphics gs, bool drawDefineOnly)
        {
            Bitmap image = null;
            switch (this.Step_Type)
            {
                case StepType.EndOther:
                case StepType.EndNotTransact:
                case StepType.EndNotAccept:
                case StepType.End:
                    image = Resource.end_step_bmp;
                    break;

                case StepType.Start:
                    image = Resource.start_step_bmp;
                    break;

                case StepType.Normal:
                case StepType.MutiFlowStart:
                case StepType.MutiFlowEnd:
                    image = Resource.step_bmp;
                    break;
            }
            gs.DrawImage(image, this.Cx, this.Cy, this.Width, this.Height);
            this.DrawTextBottomImage(gs, this.Cx, this.Cy, this.Width, this.Height);
        }

        private void DrawTextBottomImage(Graphics gs, float cx, float cy, float width, float height)
        {
            float x = 0f;
            float y = 0f;
            SolidBrush brush = new SolidBrush(Color.Green);
            this.ts.Font_Size = 10f;
            _FlowFactoryProvider.GetGraphicText(this.ts.Font, this.Sname, width - 1f, 30f, this.Cx, this.Cy + height, gs, ref x, ref y);
            gs.DrawString(this.Sname, this.ts.Font, brush, x, y);
        }

        public void ExportToXml(ref WorkFlowXmlDocumnet workFlowXmlDocumnet)
        {
            this.ExportToXml(false, ref workFlowXmlDocumnet);
        }

        public void ExportToXml(bool onlyStep, ref WorkFlowXmlDocumnet workFlowXmlDocumnet)
        {
            XmlElement newChild = workFlowXmlDocumnet.WorkFlowXmlDcoument.CreateElement("step");
            newChild.SetAttribute("wid", this.wid);
            newChild.SetAttribute("ctlid", this.CtlId);
            newChild.SetAttribute("sname", this.sname);
            newChild.SetAttribute("step_type", Convert.ToString((int)this.step_type));
            newChild.SetAttribute("op_type", this.op_type);
            newChild.SetAttribute("sync_lock", this.sync_lock);
            newChild.SetAttribute("exclusive_receive", this.exclusive_receive);
            newChild.SetAttribute("send_method", Convert.ToString((int)this.send_method));
            newChild.SetAttribute("arr", this.arr);
            newChild.SetAttribute("amr", this.amr);
            newChild.SetAttribute("adr", this.adr);
            newChild.SetAttribute("aar", this.aar);
            newChild.SetAttribute("timeout", this.timeout.ToString());
            newChild.SetAttribute("cx", this.cx.ToString());
            newChild.SetAttribute("cy", this.cy.ToString());
            newChild.SetAttribute("exalarmtime", this.exalarmtime.ToString());
            newChild.SetAttribute("single_select", this.single_select);
            newChild.SetAttribute("insteptype", Convert.ToString((int)this.insteptype));
            newChild.SetAttribute("id", this.id);
            newChild.SetAttribute("extend_type", Convert.ToString((int)this.extendtype));
            GetNode("/workflow/steps", workFlowXmlDocumnet.WorkFlowXmlDcoument).AppendChild(newChild);
            if (!onlyStep)
            {
                XmlElement element2 = workFlowXmlDocumnet.WorkFlowXmlDcoument.CreateElement("step_resources");
                newChild.AppendChild(element2);
                foreach (DictionaryEntry entry in this.resources)
                {
                    XmlElement element3 = workFlowXmlDocumnet.WorkFlowXmlDcoument.CreateElement("step_resource");
                    element3.SetAttribute("path", entry.Key.ToString());
                    element3.SetAttribute("res_value", entry.Value.ToString());
                    element2.AppendChild(element3);
                }
                IEnumerator enumerator = this.userGroups.Keys.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    XmlElement element4 = workFlowXmlDocumnet.WorkFlowXmlDcoument.CreateElement("role");
                    element4.SetAttribute("gid", enumerator.Current.ToString());
                    element4.SetAttribute("group_name", this.userGroups[enumerator.Current.ToString()].ToString());
                    newChild.AppendChild(element4);
                }
            }
        }

        public IDrawObject GetSelectRange(float x, float y, bool selectInner)
        {
            if (NearRectSegment(this.Cx, this.Cy, this.Cx + this.Width, this.Cy + this.Height, x, y))
            {
                return this;
            }
            return null;
        }
        public static bool NearRectSegment(float x1, float y1, float x2, float y2, float x, float y)
        {
            return ((((x1 <= x) && (y1 <= y)) && (x2 >= x)) && (y2 >= y));
        }
        private string GetTextWrite(StepType stepType)
        {
            switch (stepType)
            {
                case StepType.Start:
                    if (beginStep.Contains(this.wid))
                    {
                        beginStep[this.wid] = _FlowFactoryProvider.S2Int(beginStep[this.wid].ToString()) + 1;
                        break;
                    }
                    beginStep.Add(this.wid, 1);
                    break;

                case StepType.End:
                    if (endStep.Contains(this.wid))
                    {
                        endStep[this.wid] = _FlowFactoryProvider.S2Int(endStep[this.wid].ToString()) + 1;
                    }
                    else
                    {
                        endStep.Add(this.wid, 1);
                    }
                    return ("结束" + endStep[this.wid].ToString());

                default:
                    if (!jobStep.Contains(this.wid))
                    {
                        jobStep.Add(this.wid, 1);
                    }
                    else
                    {
                        jobStep[this.wid] = _FlowFactoryProvider.S2Int(jobStep[this.wid].ToString()) + 1;
                    }
                    return ("岗位" + jobStep[this.wid].ToString());
            }
            return ("开始" + beginStep[this.wid].ToString());
        }

        public bool HasGroup(string groupId)
        {
            return (this.userGroups[groupId] != null);
        }

        public bool HasResource(string rtid)
        {
            return (this.resources[rtid] != null);
        }

        public bool ImportIntoDatabase(IDataAccess ida, string newWid, bool CreateNewVesion, bool checkData, ref string html, ref string msg)
        {
            string sql = "SELECT ID FROM st_step WHERE ID='" + Id + "'";
            IDataParameter[] parameter = DataFactory.GetParameter(DatabaseType.Oracle, 1);
            parameter[0].ParameterName = "id";
            parameter[0].DbType = DbType.String;
            parameter[0].Value = this.Id;
            string str2 = string.Empty;
            DataTable table = ida.RunSql(sql, ref parameter);
            if (table.Rows.Count > 0)
            {
                str2 = table.Rows[0][0].ToString();
            }
            string wid = this.Wid;
            string id = this.Id;
            float cx = this.Cx;
            float cy = this.Cy;
            if (!(CreateNewVesion || string.IsNullOrEmpty(str2)))
            {
                sql = "UPDATE st_step SET sname=:sname,step_type=:step_type,op_type=:op_type,sync_lock=:sync_lock,exclusive_receive=:exclusive_receive,send_method=:send_method,arr=:arr,amr=:amr,adr=:adr,aar=:aar,timeout=:timeout,cx=:cx,cy=:cy,exalarmtime=:exalarmtime,single_select=:single_select,insteptype=:insteptype,extend_type=:extend_type WHERE ID=:id";
                parameter = DataFactory.GetParameter(DatabaseType.Oracle, 0x12);
                parameter[0x11].ParameterName = "id";
                parameter[0x11].DbType = DbType.String;
                parameter[0x11].Value = this.Id;
            }
            else
            {
                if (CreateNewVesion)
                {
                    id = Guid.NewGuid().ToString();
                    wid = newWid;
                }
                sql = "INSERT INTO st_step(wid,ctlId,sname,step_type,op_type,sync_lock,exclusive_receive,send_method,arr,amr,adr,aar,timeout,cx,cy,exalarmtime,single_select,insteptype,id,extend_type)  VALUES(:wid,:ctlId,:sname,:step_type,:op_type,:sync_lock,:exclusive_receive,:send_method,:arr,:amr,:adr,:aar,:timeout,:cx,:cy,:exalarmtime,:single_select,:insteptype,:id,:extend_type)";
                parameter = DataFactory.GetParameter(DatabaseType.Oracle, 20);
                parameter[0x11].ParameterName = "id";
                parameter[0x11].DbType = DbType.String;
                parameter[0x11].Value = id;
                parameter[0x12].ParameterName = "wid";
                parameter[0x12].DbType = DbType.String;
                parameter[0x12].Value = wid;
                parameter[0x13].ParameterName = "ctlId";
                parameter[0x13].DbType = DbType.String;
                parameter[0x13].Value = this.CtlId;
            }
            parameter[0].ParameterName = "sname";
            parameter[0].DbType = DbType.String;
            parameter[0].Value = this.Sname;
            parameter[1].ParameterName = "step_type";
            parameter[1].DbType = DbType.Int32;
            parameter[1].Value = this.Step_Type;
            parameter[2].ParameterName = "op_type";
            parameter[2].DbType = DbType.Int32;
            parameter[2].Value = this.Op_Type;
            parameter[3].ParameterName = "sync_lock";
            parameter[3].DbType = DbType.Int32;
            parameter[3].Value = this.Sync_Lock;
            parameter[4].ParameterName = "exclusive_receive";
            parameter[4].DbType = DbType.Int32;
            parameter[4].Value = this.Exclusive_Receive;
            parameter[5].ParameterName = "send_method";
            parameter[5].DbType = DbType.Int32;
            parameter[5].Value = this.Send_Method;
            parameter[6].ParameterName = "arr";
            parameter[6].DbType = DbType.Int32;
            parameter[6].Value = this.Arr;
            parameter[7].ParameterName = "amr";
            parameter[7].DbType = DbType.Int32;
            parameter[7].Value = this.Amr;
            parameter[8].ParameterName = "adr";
            parameter[8].DbType = DbType.Int32;
            parameter[8].Value = this.Adr;
            parameter[9].ParameterName = "aar";
            parameter[9].DbType = DbType.Int32;
            parameter[9].Value = this.Aar;
            parameter[10].ParameterName = "timeout";
            parameter[10].DbType = DbType.Single;
            parameter[10].Value = this.Timeout;
            parameter[11].ParameterName = "cx";
            parameter[11].DbType = DbType.Single;
            parameter[11].Value = this.Cx;
            parameter[12].ParameterName = "cy";
            parameter[12].DbType = DbType.Single;
            parameter[12].Value = this.Cy;
            parameter[13].ParameterName = "exalarmtime";
            parameter[13].DbType = DbType.Single;
            parameter[13].Value = this.ExAlarmTime;
            parameter[14].ParameterName = "single_select";
            parameter[14].DbType = DbType.Int32;
            parameter[14].Value = this.Single_Select;
            parameter[15].ParameterName = "insteptype";
            parameter[15].DbType = DbType.Int32;
            parameter[15].Value = this.InStepType;
            parameter[0x10].ParameterName = "extend_type";
            parameter[0x10].DbType = DbType.Int32;
            parameter[0x10].Value = this.ExtentType;
            ida.RunSql(sql, ref parameter);
            if (!CreateNewVesion)
            {
                sql = "DELETE FROM st_group_in_step WHERE wid=:wid AND StpName=:sname";
                parameter = DataFactory.GetParameter(DatabaseType.Oracle, 2);
                parameter[0].ParameterName = "wid";
                parameter[0].DbType = DbType.String;
                parameter[0].Value = this.Wid;
                parameter[1].ParameterName = "sname";
                parameter[1].DbType = DbType.String;
                parameter[1].Value = this.CtlId;
                ida.RunSql(sql, ref parameter);
            }
            foreach (DictionaryEntry entry in this.userGroups)
            {
                sql = "INSERT INTO st_group_in_step(wid,stpname,gid,step_type) VALUES(:wid,:stpname,:gid,:step_type)";
                parameter = DataFactory.GetParameter(DatabaseType.Oracle, 4);
                parameter[0].ParameterName = "stpname";
                parameter[0].DbType = DbType.String;
                parameter[0].Value = this.CtlId;
                parameter[1].ParameterName = "step_type";
                parameter[1].DbType = DbType.Int32;
                parameter[1].Value = this.Step_Type;
                parameter[2].ParameterName = "gid";
                parameter[2].DbType = DbType.String;
                parameter[2].Value = entry.Key;
                parameter[3].ParameterName = "wid";
                parameter[3].DbType = DbType.String;
                parameter[3].Value = wid;
                ida.RunSql(sql, ref parameter);
            }
            if (!CreateNewVesion)
            {
                sql = "DELETE FROM ST_RESOURCE_Right WHERE wid=:wid AND sctlid=:sctlid";
                parameter = DataFactory.GetParameter(DatabaseType.Oracle, 2);
                parameter[0].ParameterName = "wid";
                parameter[0].DbType = DbType.String;
                parameter[0].Value = wid;
                parameter[1].ParameterName = "sctlId";
                parameter[1].DbType = DbType.String;
                parameter[1].Value = this.CtlId;
                ida.RunSql(sql, ref parameter);
            }
            foreach (DictionaryEntry entry in this.resources)
            {
                sql = "INSERT INTO ST_RESOURCE_Right(id,rtid,sctlid,Wid) VALUES(:id,:rtid,:sctlid,:wid)";
                parameter = DataFactory.GetParameter(DatabaseType.Oracle, 4);
                parameter[0].ParameterName = "id";
                parameter[0].DbType = DbType.String;
                parameter[0].Value = Guid.NewGuid().ToString();
                parameter[1].ParameterName = "rtid";
                parameter[1].DbType = DbType.String;
                parameter[1].Value = entry.Value.ToString();
                parameter[2].ParameterName = "sctlid";
                parameter[2].DbType = DbType.String;
                parameter[2].Value = this.CtlId;
                parameter[3].ParameterName = "wid";
                parameter[3].DbType = DbType.String;
                parameter[3].Value = wid;
                ida.RunSql(sql, ref parameter);
            }
            return true;
        }

        private void InitData(DataRow dr)
        {
            int num;
            this.Id = dr["id"].ToString();
            this.wid = dr["Wid"].ToString();
            this.Sname = dr["Sname"].ToString();
            this.CtlId = dr["CtlId"].ToString();
            this.Cx = _FlowFactoryProvider.S2Float(dr["cx"].ToString());
            this.Cy = _FlowFactoryProvider.S2Float(dr["cy"].ToString());
            this.Step_Type = (StepType)_FlowFactoryProvider.S2Int(dr["step_type"].ToString());
            this.Op_Type = dr["op_type"].ToString();
            this.Sync_Lock = dr["sync_lock"].ToString();
            this.Exclusive_Receive = dr["exclusive_receive"].ToString();
            this.Send_Method = (SendMethod)_FlowFactoryProvider.S2Int(dr["Send_Method"].ToString());
            this.Arr = dr["arr"].ToString();
            this.Amr = dr["amr"].ToString();
            this.Adr = dr["adr"].ToString();
            this.Aar = dr["aar"].ToString();
            this.Timeout = _FlowFactoryProvider.S2Int(dr["timeout"].ToString());
            this.ExAlarmTime = _FlowFactoryProvider.S2Int(dr["ExAlarmTime"].ToString());
            this.Single_Select = dr["single_select"].ToString();
            this.InStepType = (InStepSumbitType)_FlowFactoryProvider.S2Int(dr["InStepType"].ToString());
            this.ExtentType = (StepExtendType)_FlowFactoryProvider.S2Int(dr["Extend_Type"].ToString());
            string sql = "select a.gid,b.group_name from st_group_in_step a,st_group b  Where a.gid=b.groupid And WID=:wid AND stpname=:ctlId";
            IDataParameter[] parameter = DataFactory.GetParameter(DatabaseType.Oracle, 2);
            parameter[0].ParameterName = "wid";
            parameter[0].DbType = DbType.String;
            parameter[0].Value = this.wid;
            parameter[1].ParameterName = "ctlId";
            parameter[1].DbType = DbType.String;
            parameter[1].Value = this.CtlId;
            DataTable table = _FlowFactoryProvider.dataAccess().RunSql(sql, ref parameter);
            for (num = 0; num < table.Rows.Count; num++)
            {
                DataRow row = table.Rows[num];
                if (this.userGroups[row["gid"].ToString()] == null)
                {
                    this.userGroups.Add(row["gid"].ToString(), row["group_name"].ToString());
                }
            }
            sql = "SELECT * FROM st_resource_Right WHERE WID=:wid AND sctlId=:ctlId";
            parameter = DataFactory.GetParameter(DatabaseType.Oracle, 2);
            parameter[0].ParameterName = "wid";
            parameter[0].DbType = DbType.String;
            parameter[0].Value = this.Wid;
            parameter[1].ParameterName = "ctlId";
            parameter[1].DbType = DbType.String;
            parameter[1].Value = this.CtlId;
            table = _FlowFactoryProvider.dataAccess().RunSql(sql, ref parameter);
            for (num = 0; num < table.Rows.Count; num++)
            {
                if (this.resources[table.Rows[num]["rtid"].ToString()] == null)
                {
                    this.resources.Add(table.Rows[num]["rtid"].ToString(), table.Rows[num]["rtid"].ToString());
                }
            }
            this.AddStepCount(this.Step_Type, this.Sname);
        }

        public void SetResource(string rtid)
        {
            if (this.resources[rtid] != null)
            {
                this.resources.Remove(rtid);
            }
            else
            {
                this.resources.Add(rtid, rtid);
            }
        }

        public void SetUserGroup(string groupId, string value)
        {
            if (this.userGroups[groupId] != null)
            {
                this.userGroups.Remove(groupId);
            }
            else
            {
                this.userGroups.Add(groupId, value);
            }
        }

        // Properties
        public string Aar
        {
            get
            {
                return this.aar;
            }
            set
            {
                this.aar = value;
            }
        }

        public string Adr
        {
            get
            {
                return this.adr;
            }
            set
            {
                this.adr = value;
            }
        }

        public string Amr
        {
            get
            {
                return this.amr;
            }
            set
            {
                this.amr = value;
            }
        }

        public string Arr
        {
            get
            {
                return this.arr;
            }
            set
            {
                this.arr = value;
            }
        }

        public string CtlId
        {
            get
            {
                return this.ctlId;
            }
            set
            {
                this.ctlId = value;
            }
        }

        public float Cx
        {
            get
            {
                return this.cx;
            }
            set
            {
                this.cx = value;
            }
        }

        public float Cy
        {
            get
            {
                return this.cy;
            }
            set
            {
                this.cy = value;
            }
        }

        public int ExAlarmTime
        {
            get
            {
                return this.exalarmtime;
            }
            set
            {
                this.exalarmtime = value;
            }
        }

        public string Exclusive_Receive
        {
            get
            {
                return this.exclusive_receive;
            }
            set
            {
                this.exclusive_receive = value;
            }
        }

        public StepExtendType ExtentType
        {
            get
            {
                return this.extendtype;
            }
            set
            {
                this.extendtype = value;
            }
        }

        public float Height
        {
            get
            {
                return 32f;
            }
            set
            {
            }
        }

        public string Id
        {
            get
            {
                return this.id;
            }
            set
            {
                this.id = value;
            }
        }

        public InStepSumbitType InStepType
        {
            get
            {
                return this.insteptype;
            }
            set
            {
                this.insteptype = value;
            }
        }

        public string Op_Type
        {
            get
            {
                return this.op_type;
            }
            set
            {
                this.op_type = value;
            }
        }

        public SendMethod Send_Method
        {
            get
            {
                return this.send_method;
            }
            set
            {
                this.send_method = value;
            }
        }

        public string Single_Select
        {
            get
            {
                return this.single_select;
            }
            set
            {
                this.single_select = value;
            }
        }

        public string Sname
        {
            get
            {
                return this.sname;
            }
            set
            {
                this.sname = value;
            }
        }

        public StepType Step_Type
        {
            get
            {
                return this.step_type;
            }
            set
            {
                this.step_type = value;
            }
        }

        public string Sync_Lock
        {
            get
            {
                return this.sync_lock;
            }
            set
            {
                this.sync_lock = value;
            }
        }

        public int Timeout
        {
            get
            {
                return this.timeout;
            }
            set
            {
                this.timeout = value;
            }
        }

        public Hashtable UserGroups
        {
            get
            {
                return this.userGroups;
            }
        }

        public string Wid
        {
            get
            {
                return this.wid;
            }
        }

        public float Width
        {
            get
            {
                return 32f;
            }
            set
            {
            }
        }
    }
    public class TextStyle
    {
        FlowFactoryProvider _FlowFactoryProvider = (FlowFactoryProvider)ProviderService.ProviderServiceMange.GetProvider("FlowFactoryProvider");
        // Fields
        public string Fill_Color;
        private string font_Color;
        private string font_Name;
        private float font_Size;
        private FontStyle font_Style;
        public StringAlignment H_Align;
        public string Line_Color;
        public float Line_Width;
        public string TsId;
        public StringAlignment V_Align;
        public string Vertical;

        // Methods
        public TextStyle()
        {
            this.font_Name = "";
            this.font_Size = 20f;
            this.font_Style = FontStyle.Regular;
            this.font_Color = string.Empty;
            this.TsId = "";
            this.Fill_Color = string.Empty;
            this.Line_Color = string.Empty;
            this.Line_Width = 1f;
            this.H_Align = StringAlignment.Center;
            this.V_Align = StringAlignment.Center;
            this.Vertical = "0";
            this.SetValue("");
        }

        public TextStyle(string tsId)
            : this(tsId, "")
        {
        }

        public TextStyle(XmlNode xmlTs)
        {
            this.font_Name = "";
            this.font_Size = 20f;
            this.font_Style = FontStyle.Regular;
            this.font_Color = string.Empty;
            this.TsId = "";
            this.Fill_Color = string.Empty;
            this.Line_Color = string.Empty;
            this.Line_Width = 1f;
            this.H_Align = StringAlignment.Center;
            this.V_Align = StringAlignment.Center;
            this.Vertical = "0";
            DataTable dt = XmlChangeToDataTable(xmlTs);
            if (dt.Rows.Count > 0)
            {
                this.InitData(dt);
            }
        }
        public DataTable XmlChangeToDataTable(XmlNode doc)
        {
            XmlNodeReader reader = new XmlNodeReader(doc);
            DataSet set = new DataSet();
            set.ReadXml(reader, XmlReadMode.InferSchema);
            DataTable table = set.Tables[0];
            DataTable table2 = new DataTable();
            for (int i = 0; i < table.Columns.Count; i++)
            {
                table2.Columns.Add(table.Columns[i].Caption);
            }
            foreach (DataRow row in table.Rows)
            {
                table2.ImportRow(row);
            }
            return table2;
        }
        public TextStyle(string tsId, string defaultLineColor)
        {
            DataTable table;
            this.font_Name = "";
            this.font_Size = 20f;
            this.font_Style = FontStyle.Regular;
            this.font_Color = string.Empty;
            this.TsId = "";
            this.Fill_Color = string.Empty;
            this.Line_Color = string.Empty;
            this.Line_Width = 1f;
            this.H_Align = StringAlignment.Center;
            this.V_Align = StringAlignment.Center;
            this.Vertical = "0";
            string sql = "SELECT * FROM ST_TEXT_STYLE WHERE TsId='" + tsId + "'";
            table = _FlowFactoryProvider.GetDT(sql);
            if (table.Rows.Count > 0)
            {
                this.InitData(table);
            }
            else
            {
                this.SetValue(defaultLineColor);
            }
        }

        public XmlElement ExportToXml(WorkFlowXmlDocumnet workFlowXmlDocumnet)
        {
            return this.ExportToXml(workFlowXmlDocumnet, "text_style");
        }

        public XmlElement ExportToXml(WorkFlowXmlDocumnet workFlowXmlDocumnet, string elemnetName)
        {
            float num = this.Font_Size * 2f;
            float num2 = this.Line_Width / 5f;
            XmlElement element = workFlowXmlDocumnet.WorkFlowXmlDcoument.CreateElement(elemnetName);
            element.SetAttribute("tsid", this.TsId);
            element.SetAttribute("fill_color", this.Fill_Color);
            element.SetAttribute("line_width", num2.ToString());
            element.SetAttribute("line_color", this.Line_Color);
            element.SetAttribute("font_name", this.font_Name);
            element.SetAttribute("font_size", num.ToString());
            element.SetAttribute("font_color", this.font_Color);
            element.SetAttribute("font_style", Convert.ToString((int)this.font_Style));
            element.SetAttribute("h_align", Convert.ToString((int)this.H_Align));
            element.SetAttribute("v_align", Convert.ToString((int)this.V_Align));
            element.SetAttribute("vertical", this.Vertical);
            return element;
        }

        public string ImportIntoDatabase(IDataAccess ida, ref string msg)
        {
            float num = this.Font_Size * 2f;
            float num2 = this.Line_Width / 5f;
            string sql = @"SELECT tsid FROM ST_TEXT_STYLE WHERE fill_color='" + this.Fill_Color + @"' AND line_width='" + num2 + @"'  
AND line_color='" + this.Line_Color + @"' AND font_name='" + this.Font_Name + @"' AND font_size='" + num + @"' AND font_color='" + this.Font_Color + @"'  
AND font_style='" + this.Font_Style + @"' AND h_align='" + this.H_Align + @"' AND v_align='" + this.V_Align + @"' AND vertical='" + this.Vertical + @"'";
            string str2 = string.Empty;
            DataTable table;
            ida.RunSql(sql, out table);
            if (table.Rows.Count > 0)
            {
                str2 = table.Rows[0][0].ToString();
            }
            if (string.IsNullOrEmpty(str2))
            {
                sql = "SELECT MAX(tsid)+1 FROM ST_TEXT_STYLE ";
                str2 = ida.GetValue(sql);
                if (string.IsNullOrEmpty(str2))
                {
                    str2 = "1";
                }
                sql = @"INSERT INTO ST_TEXT_STYLE(tsid, fill_color, line_width, line_color, font_name, font_size, font_color, font_style, h_align, v_align, vertical)  
VALUES('" + str2 + @"','" + this.Fill_Color + @"','" + num2 + @"','" + this.Line_Color + @"','" + this.Font_Name + @"','" + num + @"',
'" + this.Font_Color + @"','" + this.Font_Style + @"','" + this.H_Align + @"','" + this.V_Align + @"','" + this.Vertical + @"')";
                ida.RunSql(sql);
            }
            return str2;
        }

        private void InitData(DataTable dt)
        {
            
            DataRow row = dt.Rows[0];
            this.Fill_Color = row["fill_color"].ToString();
            this.Line_Width = _FlowFactoryProvider.S2Float(row["line_width"].ToString()) * 5f;
            if (this.Line_Width == 0f)
            {
                this.Line_Width = 1f;
            }
            this.Line_Color = row["line_color"].ToString();
            this.Font_Name = row["font_name"].ToString();
            this.Font_Size = _FlowFactoryProvider.S2Float(row["font_size"].ToString()) / 2f;
            this.Font_Color = row["font_color"].ToString();
            this.Font_Style = (FontStyle)_FlowFactoryProvider.S2Int(row["font_style"].ToString());
            this.H_Align = (StringAlignment)_FlowFactoryProvider.S2Int(row["H_Align"].ToString());
            this.V_Align = (StringAlignment)_FlowFactoryProvider.S2Int(row["v_align"].ToString());
            this.Vertical = row["vertical"].ToString();
        }

        private void SetValue(string defaultLineColor)
        {
            this.Fill_Color = "0";
            this.Line_Width = 1f;
            this.Line_Color = "0";
            if (!string.IsNullOrEmpty(defaultLineColor))
            {
                this.Line_Color = defaultLineColor;
            }
            this.Font_Name = "宋体";
            this.Font_Size = 12f;
            this.Font_Color = "ff000000";
            this.Font_Style = FontStyle.Regular;
            this.H_Align = StringAlignment.Center;
            this.V_Align = StringAlignment.Center;
            this.Vertical = "0";
        }

        // Properties
        public Font Font
        {
            get
            {
                return new Font(this.font_Name, this.font_Size, this.font_Style);
            }
            set
            {
                this.font_Name = value.Name;
                this.font_Size = value.Size;
                this.font_Style = value.Style;
            }
        }

        public string Font_Color
        {
            get
            {
                return this.font_Color;
            }
            set
            {
                this.font_Color = value;
            }
        }

        public string Font_Name
        {
            get
            {
                return this.font_Name;
            }
            set
            {
                this.font_Name = value;
            }
        }

        public float Font_Size
        {
            get
            {
                return this.font_Size;
            }
            set
            {
                this.font_Size = value;
            }
        }

        public FontStyle Font_Style
        {
            get
            {
                return this.font_Style;
            }
            set
            {
                this.font_Style = value;
            }
        }

        public Color FontColor
        {
            get
            {
                return _FlowFactoryProvider.StringChangeToColor(this.font_Color);
            }
            set
            {
                this.font_Color = _FlowFactoryProvider.ColorChangeToString(value);
            }
        }

        public string HtmlFillColor
        {
            get
            {
                if (this.Fill_Color.Length == 8)
                {
                    return ("#" + this.Fill_Color.Substring(2, 6));
                }
                if (this.Fill_Color.Length == 6)
                {
                    return ("#" + this.Fill_Color);
                }
                return "";
            }
        }

        public string HtmlFontColor
        {
            get
            {
                if (this.font_Color.Length == 8)
                {
                    return ("#" + this.font_Color.Substring(2, 6));
                }
                if (this.font_Color.Length == 6)
                {
                    return ("#" + this.font_Color);
                }
                return "";
            }
        }

        public string HtmlFontStyle
        {
            get
            {
                if (this.Font.Italic)
                {
                    return "italic";
                }
                return "normal";
            }
        }

        public string HtmlFontWeight
        {
            get
            {
                if (this.Font.Bold)
                {
                    return "bold";
                }
                return "normal";
            }
        }

        public string HtmlLineColor
        {
            get
            {
                if (this.Line_Color.Length == 8)
                {
                    return ("#" + this.Line_Color.Substring(2, 6));
                }
                if (this.Line_Color.Length == 6)
                {
                    return ("#" + this.Line_Color);
                }
                return "";
            }
        }

        public string HtmlTextDecoration
        {
            get
            {
                string str = "";
                if (this.Font.Strikeout)
                {
                    str = "line-through";
                }
                if (this.Font.Underline)
                {
                    return (str + " underline");
                }
                if (!this.Font.Strikeout)
                {
                    str = "none";
                }
                return str;
            }
        }

        public string TableAlign
        {
            get
            {
                switch (this.H_Align)
                {
                    case StringAlignment.Near:
                        return "left";

                    case StringAlignment.Center:
                        return "center";

                    case StringAlignment.Far:
                        return "right";
                }
                return "center";
            }
        }

        public string TableVAlign
        {
            get
            {
                switch (this.V_Align)
                {
                    case StringAlignment.Near:
                        return "top";

                    case StringAlignment.Center:
                        return "middle";

                    case StringAlignment.Far:
                        return "bottom";
                }
                return "middle";
            }
        }
    }
    public class SerialClone
    {
        // Fields
        public static SerialClone Instance = new SerialClone();

        // Methods
        public object Clone(object obj)
        {
            MemoryStream serializationStream = new MemoryStream();
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(serializationStream, obj);
            serializationStream.Position = 0L;
            return formatter.Deserialize(serializationStream);
        }
    }
    internal class Resource
{
    // Fields
    private static CultureInfo resourceCulture;
    private static ResourceManager resourceMan;

    // Methods
    internal Resource()
    {
    }

    // Properties
    internal static Bitmap back_flow_bmp
    {
        get
        {
            return (Bitmap) ResourceManager.GetObject("back_flow_bmp", resourceCulture);
        }
    }

    internal static Bitmap check
    {
        get
        {
            return (Bitmap) ResourceManager.GetObject("check", resourceCulture);
        }
    }

    [EditorBrowsable(EditorBrowsableState.Advanced)]
    internal static CultureInfo Culture
    {
        get
        {
            return resourceCulture;
        }
        set
        {
            resourceCulture = value;
        }
    }

    internal static Bitmap end_step_bmp
    {
        get
        {
            return (Bitmap) ResourceManager.GetObject("end_step_bmp", resourceCulture);
        }
    }

    internal static Bitmap end_step_bmp_a
    {
        get
        {
            return (Bitmap) ResourceManager.GetObject("end_step_bmp_a", resourceCulture);
        }
    }

    internal static Bitmap exclusive_bmp
    {
        get
        {
            return (Bitmap) ResourceManager.GetObject("exclusive_bmp", resourceCulture);
        }
    }

    internal static Bitmap flow_bmp
    {
        get
        {
            return (Bitmap) ResourceManager.GetObject("flow_bmp", resourceCulture);
        }
    }

    internal static Bitmap flow_f_bmp
    {
        get
        {
            return (Bitmap) ResourceManager.GetObject("flow_f_bmp", resourceCulture);
        }
    }

    internal static Bitmap image_list
    {
        get
        {
            return (Bitmap) ResourceManager.GetObject("image_list", resourceCulture);
        }
    }

    internal static Bitmap locker_bmp
    {
        get
        {
            return (Bitmap) ResourceManager.GetObject("locker_bmp", resourceCulture);
        }
    }

    [EditorBrowsable(EditorBrowsableState.Advanced)]
    internal static ResourceManager ResourceManager
    {
        get
        {
            if (object.ReferenceEquals(resourceMan, null))
            {
                ResourceManager manager = new ResourceManager("Antu.WorkFlowFactory.Resource", typeof(Resource).Assembly);
                resourceMan = manager;
            }
            return resourceMan;
        }
    }

    internal static Bitmap start_step_bmp
    {
        get
        {
            return (Bitmap) ResourceManager.GetObject("start_step_bmp", resourceCulture);
        }
    }

    internal static Bitmap start_step_bmp_a
    {
        get
        {
            return (Bitmap) ResourceManager.GetObject("start_step_bmp_a", resourceCulture);
        }
    }

    internal static Bitmap step_bmp
    {
        get
        {
            return (Bitmap) ResourceManager.GetObject("step_bmp", resourceCulture);
        }
    }

    internal static Bitmap step_bmp_a
    {
        get
        {
            return (Bitmap) ResourceManager.GetObject("step_bmp_a", resourceCulture);
        }
    }

    internal static Bitmap step_lock_bmp
    {
        get
        {
            return (Bitmap) ResourceManager.GetObject("step_lock_bmp", resourceCulture);
        }
    }

    internal static Bitmap step_lock_bmp_a
    {
        get
        {
            return (Bitmap) ResourceManager.GetObject("step_lock_bmp_a", resourceCulture);
        }
    }
}
    public interface IDrawObject : ICloneable
    {
        // Methods
        void Draw(Graphics gs, bool drawDefineOnly);
        void ExportToXml(ref WorkFlowXmlDocumnet workFlowXmlDocumnet);
        IDrawObject GetSelectRange(float x, float y, bool selectInner);
        bool ImportIntoDatabase(IDataAccess ida, string mainId, bool CreateNewVesion, bool CheckData, ref string html, ref string msg);

        // Properties
        float Cx { get; set; }
        float Cy { get; set; }
        float Height { get; set; }
        string Id { get; set; }
        float Width { get; set; }
    }
    public struct FlowUserStruct
    {
        public string FlowName;
        public string StepName;
        public string[] Users;
        public bool IsRound;
    }
    public class WorkFlowXmlDocumnet
    {
        // Fields
        public static WorkFlowXmlDocumnet Instance = new WorkFlowXmlDocumnet();
        private XmlDocument workFlowXmlDocumnet = new XmlDocument();

        // Methods
        public void Load(string fileName)
        {
            this.workFlowXmlDocumnet.Load(fileName);
        }

        public void Save(string fileName)
        {
            this.workFlowXmlDocumnet.Save(fileName);
        }

        // Properties
        public XmlDocument WorkFlowXmlDcoument
        {
            get
            {
                return this.workFlowXmlDocumnet;
            }
            set
            {
                this.workFlowXmlDocumnet = value;
            }
        }
    }
 

 

 

}
